using System;
using System.Collections;
using System.DirectoryServices;

namespace BEGDC.CC.Entity
{
	#region SystemBulletin

	/// <summary>
	/// SystemBulletin object for NHibernate mapped table 'SystemBulletin'.
	/// </summary>
	[Serializable]
	public class SystemBulletin : System.IComparable
		{
		#region Member Variables
		
		protected int _id;
		protected string _title;
		protected string _description;
		protected Nullables.NullableDateTime _modifiedDate;
		protected static String _sortExpression = "Id";
		protected static SortDirection _sortDirection = SortDirection.Ascending;

		#endregion

		#region Constructors

		public SystemBulletin() { }

		public SystemBulletin( string title, string description, Nullables.NullableDateTime modifiedDate )
		{
			this._title = title;
			this._description = description;
			this._modifiedDate = modifiedDate;
		}

		#endregion

		#region Public Properties

		public int Id
		{
			get {return _id;}
			set {_id = value;}
		}

		public string Title
		{
			get { return _title; }
			set
			{
				if ( value != null && value.Length > 50)
					throw new ArgumentOutOfRangeException("Invalid value for Title", value, value.ToString());
				_title = value;
			}
		}

		public string Description
		{
			get { return _description; }
			set
			{
				if ( value != null && value.Length > 2000)
					value = value.Substring(0, 2000 );
				_description = value;
			}
		}

		public Nullables.NullableDateTime ModifiedDate
		{
			get { return _modifiedDate; }
			set { _modifiedDate = value; }
		}

        public static String SortExpression
        {
            get { return _sortExpression; }
            set { _sortExpression = value; }
        }

        public static SortDirection SortDirection
        {
            get { return _sortDirection; }
            set { _sortDirection = value; }
        }
		#endregion
		
        #region IComparable Methods
        public int CompareTo(object obj)
        {
			if (!(obj is SystemBulletin))
				throw new InvalidCastException("This object is not of type SystemBulletin");
			
			int relativeValue;
			switch (SortExpression)
			{
				case "Id":
					relativeValue = this.Id.CompareTo(((SystemBulletin)obj).Id);
					break;
				case "Title":
					relativeValue = this.Title.CompareTo(((SystemBulletin)obj).Title);
					break;
				case "Description":
						relativeValue = ( this.Description != null ) ? this.Description.CompareTo(((SystemBulletin)obj).Description) : -1;
					break;
				case "ModifiedDate":
						relativeValue = ( this.ModifiedDate != null ) ? this.ModifiedDate.CompareTo(((SystemBulletin)obj).ModifiedDate) : -1;
					break;
                default:
                    goto case "Id";
			}
            if (SystemBulletin.SortDirection == SortDirection.Ascending)
				relativeValue *= -1;
			return relativeValue;
		}
		#endregion
	}

	#endregion
}
